#!/bin/bash

red="\e[35;1m"
green="\e[32;1m"
default="\e[0;39m"

curRow=1
curCol=1
colIndent=20 #测试内容显示缩进列数
bodyIndent=5 #正文和标题栏的间隔
separatorMuchNum=8 #分割线比标题多出的个数

function center ()
{
 _STR=$1
 _ROW=$2
 LEN=`echo $_STR | wc -L`
 COLS=`tput cols`
 HOLD_COL=`expr $COLS - $LEN`
 NEW_COL=`expr $HOLD_COL / 2`
 tput cup $_ROW $NEW_COL
 echo -en $_STR
}

function getCurPos()
{
   echo -en "\033[6n"
   #echo -en "\E[6n"
   read -sdR pos 
   pos=${pos#*[}
   #echo "$pos"
   #array=(${pos//\;/})
   OLD_IFS="$IFS"
   IFS=";"
   array=($pos)
   IFS="$OLD_IFSS"
   num=${#array[@]}
   #echo "num: $num"
   curRow=${array[0]}
   curCol=${array[1]} 
   #echo "row:$curRow, col:$curCol"
}

function getCurPosIndent()
{
    getCurPos
    tput cup $curRow $colIndent
}

function LOG_NOTICE()
{        
    echo -e "\033[34m${1}\033[0m"
}  
function LOG_ERROR()
{        
    echo -e "\033[4m\033[1m\033[33mERROR:\033[0m\033[33m${1}\033[0m"
    echo "EXP_VAL_TEST01:${EXP_VAL_TEST01}"
}

function readIni()
 {
    file=$1;section=$2;item=$3;
    val=$(awk -F '=' '/\['${section}'\]/{a=1} (a==1 && "'${item}'"==$1){a=0;print $2}' ${file}) 
    echo ${val}
}

function writeIni() 
{
    file=$1;section=$2;item=$3;val=$4
    awk -F '=' '/\['${section}'\]/{a=1} (a==1 && "'${item}'"==$1){gsub($2,"'${val}'");a=0} {print $0}' ${file} 1<>${file}
}

function readIniSections() 
{
    file=$1;
    val=$(awk '/\[/{printf("%s ",$1)}' ${file} | sed 's/\[//g' | sed 's/\]//g')
    echo ${val}
}
